import requests

class HttpRequest:
    def __init__(self):
        self.session = requests.sessions.session()

    def request(self,method,url,data,headers):
        try:
            if method.upper() == "POST":
                result = self.session.request(method=method,url =url,data=data,headers=headers)
                result_time = result.elapsed.total_seconds()
                return result,result_time
            elif method.upper() == "GET":
                result = self.session.request(method=method,url=url,params=data,headers=headers)
                result_time = result.elapsed.total_seconds()
                return  result,result_time
            else:
                print("请求方式错误！")
        except Exception as e :
            print("请求错误".format(e))
            return result,result_time

